package net.lainiao.leetcode;

import java.util.Stack;

public class LintCode12 {

    //最小值操作的栈
    public static void main(String[] args) {
        LintCode12 obj=new LintCode12();
        obj.push(1);
        System.out.println(obj.pop());
        obj.push(2);
        obj.push(3);
        System.out.println(obj.min());
        obj.push(1);
        System.out.println(obj.min());
    }


    public LintCode12() {

    }

    private Stack<Integer> mins=new Stack<>();
    private Stack<Integer> stack=new Stack<>();

    public void push(int val){
        stack.push(val);
        if(!mins.empty()){
            int tem=mins.get(mins.size()-1);
            if(val>tem){
                val=tem;
            }
        }
        mins.push(val);
    }

    public int pop(){
        int res=stack.pop();
        mins.pop();
        return res;
    }

    public int min(){
        return mins.get(mins.size()-1);
    }

}
